import requset from 'utils/request'

/**
 * 获取文章列表
 * @returns
 */
export const getArticleList = (params) =>
  requset({ url: '/mp/articles', params })

/**
 * 删除文章
 * @param {*} params
 */
export const delArticle = (params) =>
  requset({ url: '/mp/articles/' + params, method: 'DELETE' })

/**
 * 新增文章
 * @param {*} data title content cover ：{ type images } channel_id
 * @param {*} draft 是否为草稿 默认false
 * @returns
 */
export const addArticle = (data, draft = false) => {
  return requset({
    url: '/mp/articles/',
    method: 'POST',
    params: {
      draft,
    },
    data,
  })
}

/**
 * 根据id 获取文章详情
 * @param {*} id
 * @returns
 */
export const getArticleByID = (id) => {
  return requset({
    url: '/mp/articles/' + id,
    method: 'GET',
  })
}

/**
 * 根据id 编辑文章
 * @param {*} data
 * @param {*} draft
 * @returns
 */
export const editArticleByID = (data, id, draft = false) => {
  return requset({
    url: '/mp/articles/' + id,
    method: 'PUT',
    params: {
      draft,
    },
    data,
  })
}
